

package pipeline.fragment;

import javax.vecmath.Color3f;
import javax.vecmath.Vector2f;

import pipeline.misc.Fragment;
import pipeline.misc.FrameBuffer;

/**
 * This FP works just like the PhongShadedFP, but also incorporates a texture.
 *
 * @author ags
 */
public class TexturedPhongFP extends PhongShadedFP
{
        // Texture color
        Color3f texturec = new Color3f();
       
       
        public int nAttr()
        {
                return 11;
        }
       
        public void fragment(Fragment frag, FrameBuffer frameb)
        {
                float z = frag.attrs[0];
               
                if(z >= frameb.getZ(frag.x, frag.y)) {
                    return;
                }

                Color3f c = colorForFragment(frag);
               
                texture.sample(new Vector2f(frag.attrs[10], frag.attrs[11]), texturec);
               
                frameb.set(frag.x, frag.y, texturec.x*c.x, texturec.y*c.y, texturec.z*c.z, z);
        }
}
